import {
  getRequest,
  putRequest,
  postRequest,
  commonUrl
} from "@/libs/axios";

// 校验
export async function verifyFile(identifier) {
  return await getRequest(`${commonUrl}/common/common/v1/minio/tasks/${identifier}`);
}
// 初始化
export async function initTask(initTaskData) {
  let headers = { "Content-Type": "application/json" };
  return await postRequest(`${commonUrl}/common/common/v1/minio/tasks`, initTaskData, headers);
}
// 获取分片上传地址并上传
export async function preSignUrl(chunksList, identifier, partNumber) {
  let res = await getRequest(`${commonUrl}/common/common/v1/minio/tasks/${identifier}/${partNumber}`);
  const params = chunksList[partNumber - 1];
  let headers = { "Content-Type": "application/octet-stream" }
  return await putRequest(res.data, params, headers, 60 * 60 * 1000);// 一小时
}
// 合并分片
export async function mergeChunks(identifier) {
  let headers = { "Content-Type": "application/json" };
  return await postRequest(`${commonUrl}/common/common/v1/minio/tasks/merge/${identifier}`, {}, headers);
}
